<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>
	<script>
		let box = document.getElementById("box");
		let timer = null;
		let speed = 0;
		box.onmouseover = function() {
			startAnimation(this,0)
		}
		box.onmouseout = function() {
			startAnimation(this,-200)
		}
		function startAnimation(obj,end) {
			clearInterval(timer);
			speed = end > box.offsetLeft : 5 : -5;
			timer = setInterval(function() {
				if(obj.offsetLeft === end) {
					clearInterval(timer);
				}else{
					obj.style.left = obj.offsetLeft + speed + "px";
				}
			},30);
		}
	</script>
</html>